

package top.continew.admin.controller.question;

import org.springframework.web.bind.annotation.*;
import top.continew.admin.question.manger.service.model.*;
import top.continew.admin.question.manger.service.SpotCheckService;
import top.continew.starter.web.model.R;

@RestController
@RequestMapping("spotCheck")
public class SpotCheckController {

    private SpotCheckService spotCheckService;

    public SpotCheckController(SpotCheckService spotCheckService) {
        this.spotCheckService = spotCheckService;
    }

    @PostMapping
    public R addSpotCheck(@RequestBody SpotCheck spotCheck) throws Exception {
        spotCheckService.addSpotCheck(spotCheck);
        return R.ok();
    }

    @PostMapping("test")
    public R addTestSpotCheck(@RequestBody TestSpotCheck testSpotCheck) throws Exception {
        spotCheckService.addTestSpotCheck(testSpotCheck);
        return R.ok();
    }

    @GetMapping("test")
    public R getTestSpotCheck(QueryTestSpotCheck queryTestSpotCheck) throws Exception {
        return R.ok(spotCheckService.getTestSpotCheck(queryTestSpotCheck));
    }

    @PostMapping("/batchNo:{batchNo}")
    public R addSpotCheckAgain(@PathVariable String batchNo) throws Exception {
        spotCheckService.addSpotCheckAgain(batchNo);
        return R.ok();
    }

    @PostMapping("/batchNo:{batchNo}/revoke")
    public R revoke(@PathVariable String batchNo) throws Exception {
        spotCheckService.revoke(batchNo);
        return R.ok();
    }

    @GetMapping
    public R getSamplePool(SamplePoolQuery samplePoolQuery) throws Exception {
        return R.ok(spotCheckService.getSamplePool(samplePoolQuery));
    }

    @PutMapping("/{id}")
    public R checking(@PathVariable Long id, @RequestParam String status) throws Exception {
        spotCheckService.checking(id, status);
        return R.ok();
    }

    @GetMapping("/batchNo:{batchNo}/upAndDown")
    public R queryUpAndDown(@PathVariable String batchNo, @RequestParam Long id) throws Exception {
        return R.ok(spotCheckService.queryUpAndDown(batchNo, id));
    }

    @GetMapping("batch")
    public R queryBatch(BatchQuery batchQuery) throws Exception {
        return R.ok(spotCheckService.queryBatch(batchQuery));
    }

    @PutMapping("/batchNo:{batchNo}/reject")
    public R reject(@PathVariable String batchNo, String msg) throws Exception {
        spotCheckService.reject(batchNo, msg);
        return R.ok();
    }

    @PutMapping("/batchNo:{batchNo}/pass")
    public R pass(@PathVariable String batchNo) throws Exception {
        spotCheckService.pass(batchNo);
        return R.ok();
    }

}
